Skip to content

Add SwiftUI native read bindings#845

Closed
ubermensch1218 wants to merge 3 commits into
edwardkim:mainfrom
ubermensch1218:swiftui-native-read
Closed

Add SwiftUI native read bindings#845
ubermensch1218 wants to merge 3 commits into
edwardkim:mainfrom
ubermensch1218:swiftui-native-read

Conversation

@ubermensch1218
Copy link
Copy Markdown

@ubermensch1218 ubermensch1218 commented May 12, 2026

Summary

  • add a Swift Package wrapper for the native RHWP C ABI
  • package the native library as an Apple XCFramework for Swift app integration
  • add direct HWP text reads via rhwp_read_text and expose RhwpDocumentTextView for SwiftUI display

Verification

  • cargo test --manifest-path bindings/Native/Cargo.toml
  • cargo build --manifest-path bindings/Native/Cargo.toml
  • swift test -Xlinker -L../../bindings/Native/target/debug
  • ./scripts/package-swift-xcframework.sh
  • unpacked generated XCFramework ZIP and linked the macOS slice to call rhwp_read_text against samples/KTX.hwp
  • launched a temporary macOS SwiftUI smoke app using RhwpDocumentTextView and confirmed HWP text rendered on screen

Notes

  • iOS Simulator app target runtime smoke is still not covered; the generated XCFramework includes iOS device and Apple Silicon simulator slices.

강정석 added 3 commits May 12, 2026 14:44
The native binding crate already provides a stable C ABI for text and Markdown export, so the Swift port starts as a thin SwiftPM package over that ABI instead of duplicating parser logic. The wrapper keeps file-based export semantics intact while giving Swift callers typed results and errors.

Constraint: Existing portable surface is the bindings/Native C ABI

Rejected: Rewrite the parser in Swift | would duplicate the Rust document model before the ABI is proven in apps

Confidence: high

Scope-risk: narrow

Directive: Keep Swift API additions aligned with bindings/Native symbols until an XCFramework packaging step is introduced

Tested: cargo build --manifest-path bindings/Native/Cargo.toml

Tested: swift test -Xlinker -L../../bindings/Native/target/debug

Not-tested: iOS app bundle/XCFramework runtime packaging
Swift app integration needs an Apple-native binary artifact, so the native FFI crate now emits a static library and the release helper assembles device, simulator, and macOS slices into RhwpNative.xcframework with a zipped archive and checksum.

Constraint: Xcode consumes native Rust code most cleanly through XCFramework artifacts

Rejected: Commit generated XCFramework output | binary release artifacts should stay under ignored dist/swift

Confidence: high

Scope-risk: narrow

Directive: Keep the generated archive out of git; rerun scripts/package-swift-xcframework.sh for release assets

Tested: ./scripts/package-swift-xcframework.sh

Tested: swift test -Xlinker -L../../bindings/Native/target/debug

Not-tested: importing the generated XCFramework into a real iOS app target
Swift app callers need document content in memory, not a TXT export side effect. The native ABI now exposes rhwp_read_text, Swift decodes that into page models, and the package includes a SwiftUI text view that loads an HWP URL and displays extracted pages.

Constraint: SwiftUI display should not depend on temporary export files

Rejected: Reuse rhwp_export_text for UI display | it writes TXT files and returns paths instead of document content

Confidence: high

Scope-risk: moderate

Directive: Keep read APIs side-effect free; export APIs remain the file-writing surface

Tested: cargo test --manifest-path bindings/Native/Cargo.toml

Tested: cargo build --manifest-path bindings/Native/Cargo.toml

Tested: swift test -Xlinker -L../../bindings/Native/target/debug

Tested: ./scripts/package-swift-xcframework.sh

Tested: unpacked XCFramework ZIP macOS slice linked to rhwp_read_text against samples/KTX.hwp

Not-tested: rendering inside a live iOS simulator app target
@edwardkim edwardkim self-requested a review May 13, 2026 09:06
@edwardkim edwardkim added the enhancement New feature or request label May 13, 2026
edwardkim pushed a commit that referenced this pull request May 13, 2026
…wpDocumentTextView

PR #845 (@ubermensch1218, rhwp 첫 PR) cherry-pick.
base main → devel 경로 보정하여 cherry-pick.

신규:
- bindings/swift/ — SwiftPM package (CRhwpNative modulemap + Rhwp Swift wrapper)
- bindings/swift/Sources/Rhwp/Rhwp.swift — RhwpDocument (open/readText/exportText/exportMarkdown)
- bindings/swift/Sources/Rhwp/RhwpDocumentTextView.swift — SwiftUI 텍스트 뷰
- bindings/swift/Tests/RhwpTests/ — Swift 테스트
- scripts/package-swift-xcframework.sh — XCFramework 패키징 스크립트
- bindings/Native/src/lib.rs — rhwp_read_text FFI 함수 신규

검증:
- cargo test --release --lib: 1246 passed (회귀 0)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
edwardkim pushed a commit that referenced this pull request May 13, 2026
@edwardkim edwardkim closed this May 13, 2026
edwardkim pushed a commit that referenced this pull request May 13, 2026
- bindings/swift/Examples/read_text_ffi.swift — rhwp_read_text FFI 예제
  (HWP 파일 텍스트를 페이지별 JSON으로 읽어 출력)
- bindings/swift/README.md — Examples 섹션 추가 (실행 방법 3가지)

검증: swift bindings/swift/Examples/read_text_ffi.swift → KTX.hwp 27페이지 텍스트 정상 출력

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@edwardkim
Copy link
Copy Markdown
Owner

Welcome to the rhwp project, @ubermensch1218! 🎉

This is your first PR and we really appreciate the initiative — adding a Swift Package wrapper with RhwpDocumentTextView and XCFramework packaging is a great contribution. We've cherry-picked your changes into the devel branch and synced them to ios/devel.

What was merged

  • bindings/swift/ — SwiftPM package (Rhwp wrapper + RhwpDocumentTextView + tests)
  • bindings/Native/src/lib.rsrhwp_read_text FFI function
  • scripts/package-swift-xcframework.sh — XCFramework packaging script
  • Author preserved: 강정석 <jskang@MAKBOOK.local>

We also added an example script and updated the README as a follow-up:

  • bindings/swift/Examples/read_text_ffi.swift — demonstrates direct FFI usage
  • bindings/swift/README.md — Examples section with usage guide

Branch policy for future Swift/iOS work

For any future Swift or iOS-related PRs, please target the ios/devel branch instead of main or devel. The ios/devel branch is where all Apple platform work lives (including our existing iOS app "알한글"). We periodically sync develios/devel to keep Rust core changes in sync.

# When creating a PR for Swift/iOS work:
gh pr create --repo edwardkim/rhwp --base ios/devel --head your-branch --title "..."

How to run the Swift tests locally

# 1. Build the native FFI library
cargo build --manifest-path bindings/Native/Cargo.toml

# 2. Run Swift package tests (macOS)
cd bindings/swift
swift test -Xlinker -L../../bindings/Native/target/debug

# 3. Run the FFI example script (reads samples/KTX.hwp)
cargo build --manifest-path bindings/Native/Cargo.toml --release
swift bindings/swift/Examples/read_text_ffi.swift

# 4. Read a specific file and page
swift bindings/swift/Examples/read_text_ffi.swift samples/aift.hwp 0

All 4 Swift tests pass on our environment (macOS, Apple Silicon).

Thank you for the contribution, and we look forward to more! If you have questions about the project structure or ios/devel workflow, feel free to open a discussion or issue.

@ubermensch1218
Copy link
Copy Markdown
Author

ubermensch1218 commented May 13, 2026 via email

@ubermensch1218
Copy link
Copy Markdown
Author

Thanks for the detailed note and for preserving authorship. Noted on the branch policy. I’ll target ios/devel for future Swift/iOS-related PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants